<template>
	<view>
		<view class='my-order'>
		
			<!-- <view class='nav acea-row row-around'>
				<view v-for="item in shopList">
				<view class='item'   :class='item.orderStatus==orderStatus? "on": ""' @click="statusClick(item.orderStatus)">
					<view>{{item.name}}</view>
				</view>
				</view>
				
				
			</view> -->
			<u-tabs :list="shopList" :is-scroll=true :current="current" @change="tabsChange" ref="tabs"
				active-color="#aa0000" inactive-color="#606266"></u-tabs>
			
			
			<view class="list"  v-for="item in List">
				<view class="topBox" @click="goToDetail(item)">
					
				
				<view class="info_img">
					<img :src="item.productImage" alt="" style="height: 100%;width: 100%;"/>
				</view>
				<view class="right_box">			
					<view class="list_txt">
						<view class="">{{item.productName}}</view>
						<view class="numPic">{{item.status==0?$t('order.purchased'):item.status==1?$t('order.shipped'):item.status==2?$t('order.received-goods'):$t('order.complete')}}</view>
					</view>
					
					<!-- <view class="countDown">
						<u-count-down ref="uCountDown" color="#d9001b" :timestamp="item.secondFailureTime" style="color: red;"></u-count-down>
						后订单失效(倒计时)
						</view> -->
					<view class="num_Box">
					<view class="num_pic">{{item.productPrice}} u</view>
					<!-- <view class="earnings">收益 100usdt</view> -->
					</view>
					
				</view>
		</view>
				<view class="creat">
					<view class="time">
						{{item.failureTime}}
					</view>
				<!-- 	<view class="btn_flex" v-if="item.status == 2">
						<button type="primary" size="mini" @click="submit(item.id)">确认发货</button>
						<button type="primary" size="mini" class="checkBtn">查看凭证</button>
					</view> -->
					
				<!-- 	<view class="btn_flex" v-if="item.status == 0">
						<button type="primary" size="mini" @click="submit(item.id)">上传凭证</button>
						
					</view> -->
				</view>
				
			</view>
			<u-popup v-model="showPopup" mode="bottom" :closeable=true :mask-close-able=false height="450px">
				<view class="record_tit">{{$t('order.input-pay-password')}}</view>
				<u-message-input style="margin-top: 45px;" :maxlength="6" @finish="finishNew" @change="change"
					:focus="true">
				</u-message-input>
			</u-popup>
			
			
			<view class='loadingicon acea-row row-center-wrapper' v-if="List.length>0">
				<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
			</view>
			<view v-if="List.length == 0">
				<emptyPage :title="noOrderData"></emptyPage>
			</view>
		</view>
		<view class='noCart' v-if="List.length == 0 && page > 1">
			<view class='pictrue'>
				<image src='/images/noOrder.png'></image>
			</view>
		</view>
		
		<home></home>
		
	</view>
</template>

<script>
	import {
		getOrderList,
		orderData,
		orderCancel,
		orderDel
	} from '@/api/order.js';
	
	import {
		userWarehousePay,
		userWarehouseSell,
		userProduct,
		recordPwd,
		submitInfo
	} from '@/api/new.js';
	
	import {
		openOrderSubscribe
	} from '@/utils/SubscribeMessage.js';
	import home from '@/components/home';
	import payment from '@/components/payment';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	
	import emptyPage from '@/components/emptyPage.vue'
	export default {
		components: {
			payment,
			home,
			emptyPage,
			// #ifdef MP
			authorize
			// #endif
		},
		data() {
			return {
				noOrderData: this.$t('order.no-order-tips'),
				shopId:null,
				showPopup: false,
				loading: false, //是否加载中
				loadend: false, //是否加载完毕
				loadTitle: this.$t('public.tips.load-more'), //提示语
				orderList: [], //订单数组
				orderData: {}, //订单详细统计
				orderStatus: 0, //订单状态
				shopStatus:0,
				params: { //分页
					page: 1,
					limit: 10,
				},
				page: 1,
				limit: 20,
				pay_close: false,
				pay_order_id: '',
				totalPrice: '0',
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				List:[],
				// 0：待发货；1：待收货；2：已收货3：已完成
				shopList:[
				{
					name: this.$t('order.purchased'),
					orderStatus:0,
					value:0
				},{
					name: this.$t('order.shipped'),
					orderStatus:1,
					value:1
				},{
					name: this.$t('order.received-goods'),
					orderStatus:2,
					value:2
				},{
					name: this.$t('order.complete'),
					orderStatus:3,
					value:3
				}],
				current: 0,
			};
		},
		computed: mapGetters(['isLogin', 'userInfo']),
		onShow() {
			console.log(123);
			// if (this.isLogin) {
			// 	this.loadend = false;
			// 	this.page = 1;
			// 	this.$set(this, 'orderList', []);
			// 	this.getOrderData();
			// 	this.getOrderList();
			// 	this.payMode[1].number = this.userInfo.nowMoney;
			// 	this.$set(this, 'payMode', this.payMode);
			// } else {
			// 	toLogin();
			// }
			this.addressData = uni.getStorageSync("addressNetwork")
			console.log(this.addressData,'addressData');
			this.getList()
			uni.setNavigationBarTitle({
				title:this.$t('user.my-product')
			})
		},
		methods: {
			tabsChange(index){
				
				// console.log(index, this.orderStatus);
				// // if (index == this.orderStatus) return
				// switch (index) {
				// 	case 0:
				// 		this.orderStatus = 0
				// 		this.shopStatus = 0;
				// 		break;
				// 	case 1:
				// 		this.orderStatus = 1
				// 		this.shopStatus = 1;
				// 		break;
				// 	case 2:
				// 		this.orderStatus = 3
				// 		this.shopStatus = 3;
				// 		break;
				// 	case 3:
				// 		this.orderStatus = 4
				// 		this.shopStatus = 4;
				// 		break;
					
				// }
				// console.log(index, 'index');
				this.current = index
				this.orderStatus = index
				this.loadend = false;
				this.hotScroll = false;
				this.List = []
				this.params.page = 1
			
				this.getList()
				
			},
			submit(id) {	
				this.shopId = id
				if (this.addressData) {
					this.showPopup = true
				} else {
			
					this.$util.Tips({
						title: '请先补充收款信息~'
					});
			
				}
			
				// this.successInfo  = 2
			},
			finishNew(e) {
				let that = this
				this.oldPwd = e
				uni.showLoading({
					title: '请稍等'
				});
				let data = {
					oldPwd: e
				}
				recordPwd(data).then(res => {
			
					uni.hideLoading();
					let data = {
						productId: that.shopId,
						addressId: that.addressData.id
					}
					submitInfo(data).then(res => {
						// console.log(res, 'submitInfo成功了');
						let order = res.data.message
						that.showPopup = false
						uni.showModal({
							title: '提示',
							content: '您已支付成功,是否查看订单详情?',
							confirmText: '查看',
							success(res) {
								if (res.confirm) {
									uni.redirectTo({
										url: '/pages/new_Shop/submitOrder/submitInfo?orderInfo=' +
											order
									})
								} else if (res.cancel) {
									return that.$util.Tips({
										title: '已取消！'
									});
								}
			
							}
						})
			
			
					}).catch(err => {
						that.$util.Tips({
							title: err
						});
					});
			
			
			
			
				}).catch(res => {
					uni.hideLoading();
					that.$util.Tips({
						title: res
					});
				});
			
			},
			goToDetail(){
				
			},
			getList(){
				let that = this
				let ch = uni.getStorageSync('AppLocale').code
				let data ={
					status:this.orderStatus,
					page:that.params.page,
					limit:that.params.limit,
				}
				userProduct(data).then(res=>{
					console.log(res,'LLLLL');
					if(that.hotScroll) return
					that.params.page++
					that.hotScroll = res.data.list.length < that.params.limit
					that.loading = false;
					
					
					let arr = [...this.List,...res.data.list]
								
								arr.forEach(item => {
									if(item.productName){
									if (item.productName.includes('|')) {
										if (ch == "en") {
											item.productName = item.productName.split('|')[0]
										} else {
											item.productName = item.productName.split('|')[1]
										}
					}
									}
								
								})
								
								
								this.List = arr
					
				})
			},
			/**
			 * 切换类型
			 */
			statusClick: function(status) {
				if (status == this.orderStatus) return;
				this.orderStatus = status;
				this.loadend = false;
				this.page = 1;
				this.$set(this, 'orderList', []);
				// this.getOrderList();
				this.getList()
			},
			/**
			 * 获取订单列表
			 */
			getOrderList: function() {
				let that = this;
				if (that.loadend) return;
				if (that.loading) return;
				that.loading = true;
				that.loadTitle = this.$t('public.tips.load-more');
				getOrderList({
					type: that.orderStatus,
					page: that.page,
					limit: that.limit,
				}).then(res => {
					let list = res.data.list || [];
					let loadend = list.length < that.limit;
					that.orderList = that.$util.SplitArray(list, that.orderList);
					that.$set(that, 'orderList', that.orderList);
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? this.$t('public.tips.no-data') : this.$t('public.tips.load-more');
					that.page = that.page + 1;
				}).catch(err => {
					that.loading = false;
					that.loadTitle = this.$t('public.tips.load-more');
				})
			},

			/**
			 * 删除订单
			 */
			delOrder: function(order_id, index) {
				let that = this;
				orderDel(order_id).then(res => {
					that.orderList.splice(index, 1);
					that.$set(that, 'orderList', that.orderList);
					that.$set(that.orderData, 'unpaid_count', that.orderData.unpaid_count - 1);
					that.getOrderData();
					return that.$util.Tips({
						title: '删除成功',
						icon: 'success'
					});
				}).catch(err => {
					return that.$util.Tips({
						title: err
					});
				})
			},
		},
		onReachBottom: function() {
			this.getList()
		}
	}
</script>

<style scoped lang="scss">
	.record_tit {
		font-size: 18px;
		font-weight: bold;
		text-align: center;
		padding: 20px 0;
	}
	
	.my-order .header {
		height: 250rpx;
		padding: 0 30rpx;
	}

	.my-order .header .picTxt {
		height: 190rpx;
	}

	.my-order .header .picTxt .text {
		color: rgba(255, 255, 255, 0.8);
		font-size: 26rpx;
		font-family: 'Guildford Pro';
	}

	.my-order .header .picTxt .text .name {
		font-size: 34rpx;
		font-weight: bold;
		color: #fff;
		margin-bottom: 20rpx;
	}

	.my-order .header .picTxt .pictrue {
		width: 122rpx;
		height: 109rpx;
	}

	.my-order .header .picTxt .pictrue image {
		width: 100%;
		height: 100%;
	}

	.my-order .nav {
		background-color: #fff;
		// width: 690rpx;
		// height: 140rpx;
		border-radius: 14rpx;
		position: sticky;
		top: 0;
		z-index: 99;
		// margin: -60rpx auto 0 auto;
	}

	.my-order .nav .item {
		text-align: center;
		// font-size: 26rpx;
		color: #282828;
		padding: 26rpx 0;
	}

	.my-order .nav .item.on {
		// font-weight: bold;
		// border-bottom: 5rpx solid #e93323;
		/* #ifdef H5 || MP */
		font-weight: bold;
		/* #endif */
		border-bottom: 5rpx solid $theme-color;
	}

	.my-order .nav .item .num {
		margin-top: 18rpx;
	}

	.my-order .list {
		// width: 690rpx;
		// margin: 14rpx auto 0 auto;
		background-color: #fff;
		margin: 10px;
		padding: 8px;
		
		.topBox{
			display: flex;
		
			.right_box{
				flex: 1;
				display: flex;
				flex-direction: column;
				.countDown{
					color: rgb(217,0,27);
					padding:3px 0 10px 0;
				}
				.num_Box{
					display: flex;
					.num_pic{
						font-size: 18px;
						font-weight: 700;
					}
					.earnings{
						margin: 3px 8px;
						color: rgb(115,150,58);
					}
				}
				
			}
			.info_img{
				// background-color: aqua;
				width: 70px;
				height: 70px;
				margin-right: 10px;
				img{
					width: 70px;
					height: 70px;
				}
			}
			.list_txt{
				display: flex;
				justify-content: space-between;
				
				flex: 1;
			}
		}
		.creat{
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin: 6px 0;
			.btn_flex{
				display: flex;
				.checkBtn{
					margin-left: 10px;
				}
			}
		}
	}

	.my-order .list .item {
		background-color: #fff;
		border-radius: 14rpx;
		margin-bottom: 14rpx;
	}

	.my-order .list .item .title {
		height: 84rpx;
		padding: 0 24rpx;
		border-bottom: 1rpx solid #eee;
		font-size: 28rpx;
		color: #282828;
	}

	.my-order .list .item .title .sign {
		font-size: 24rpx;
		padding: 0 13rpx;
		height: 36rpx;
		margin-right: 15rpx;
		border-radius: 18rpx;
	}

	.my-order .list .item .item-info {
		padding: 0 24rpx;
		margin-top: 22rpx;
	}

	.my-order .list .item .item-info .pictrue {
		width: 120rpx;
		height: 120rpx;
	}

	.my-order .list .item .item-info .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 14rpx;
	}

	.my-order .list .item .item-info .text {
		width: 500rpx;
		font-size: 28rpx;
		color: #999;
	}

	.my-order .list .item .item-info .text .name {
		width: 350rpx;
		color: #282828;
	}

	.my-order .list .item .item-info .text .money {
		text-align: right;
	}

	.my-order .list .item .totalPrice {
		font-size: 26rpx;
		color: #282828;
		text-align: right;
		margin: 27rpx 0 0 30rpx;
		padding: 0 30rpx 30rpx 0;
		border-bottom: 1rpx solid #eee;
	}

	.my-order .list .item .totalPrice .money {
		font-size: 28rpx;
		font-weight: bold;
	}

	.my-order .list .item .bottom {
		height: 107rpx;
		padding: 0 30rpx;
	}

	.my-order .list .item .bottom .bnt {
		width: 176rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		color: #fff;
		border-radius: 50rpx;
		font-size: 27rpx;
	}

	.my-order .list .item .bottom .bnt.cancelBnt {
		border: 1rpx solid #ddd;
		color: #aaa;
	}

	.my-order .list .item .bottom .bnt~.bnt {
		margin-left: 17rpx;
	}

	.noCart {
		margin-top: 171rpx;
		padding-top: 0.1rpx;
	}

	.noCart .pictrue {
		width: 414rpx;
		height: 336rpx;
		margin: 78rpx auto 56rpx auto;
	}

	.noCart .pictrue image {
		width: 100%;
		height: 100%;
	}
</style>
